home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************
- CDictionary.h
-
- Subclass of CCollection that implements a dictionary. See
- CDictionary.doc for more info
-
- SUPERCLASS = CCollection
- ********************************************************************/
-
-
- #define _H_CDictionary
-
- #include "CCollection.h"
- #include "defs.h"
-
- typedef uInt32 (*MapProc)( void *key);
- typedef Boolean (*CompareProc)( void *key1, void *key2);
-
- typedef struct tAssociation
- {
- CObject *value;
- char key[];
-
- } tAssociation, *tAssociationPtr;
-
- /* Iterator function types for dictionary. DictIterators
- are passed to DoForEach. Do For each calls a DictIterator
- with a pointer to an association. DictIterator1 should be
- passed to DoForEach1. It is presented with a pointer to
- an association and a longword parameter */
-
- typedef void (*DictIterator)( tAssociationPtr);
- typedef void (*DictIterator1)( tAssociationPtr, Int32);
-
-
- struct CDictionary : CCollection
- {
- /* instance variables */
-
- Int16 keySize; /* size of keys */
- Int16 slotSize; /* size of each slot (bucket) = keySize + sizeof(ptr to object) */
- Int32 tableSize; /* current size of table */
- Int32 slotsLeft; /* number of empty slots in table */
- Handle table; /* hash table */
-
- MapProc map; /* the mapping function */
- CompareProc compare; /* the comparison function */
-
- struct CDataFile *itsFile; /* not-nil while reading or writing a file */
-
- /* public methods */
-
- virtual Boolean IDictionary( Int16 keySize, MapProc map, CompareProc compare,
- Int32 initialSize);
-
- virtual void Dispose( void);
- virtual void DisposeAll( void);
- virtual void DisposeItems( void);
-
- virtual void Add( void *key, CObject *value);
- virtual void AddAll( CDictionary *aDictionary);
- virtual void Remove( void *key);
-
- virtual CObject *Lookup( void *key);
-
- virtual Boolean IncludesKey( void *key);
- virtual Boolean IncludesValue( CObject *anObject);
-
- virtual void DoForEach( DictIterator actionProc);
- virtual void DoForEach1( DictIterator1 actionProc, Int32 aParam);
-
- virtual CObject *Copy( void);
-
- /* private methods */
-
- virtual void MoreSlots( void);
- virtual Int32 _lookup( void *key);
-
- };
-